package com.lzq.controller;

import com.alibaba.fastjson.JSON;
import com.lzq.config.RequestJson;
import com.lzq.model.SysUser;
import com.lzq.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 2019/1/30 15:44 by 刘赵强
 **/
@RequestMapping("/controller")
@Controller
@Slf4j
public class TestController {

    @Autowired
    private TestService testService;

    @ResponseBody
    @RequestMapping("/test")
    public String test(@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                       @RequestParam(value = "pageNo") Integer pageNo,
                       @Validated SysUser sysUser, String phone, String password
    ) {
        log.info("test");
        log.info("每页显示{}", pageSize);
        log.info("参数pageNO={},name={}", pageNo, sysUser.getName());
        log.info("phone={}", phone);
        try {
            testService.test(phone, password);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return "success";
    }

    @RequestMapping("/new/test")
    @ResponseBody
    public Object newTest( @RequestJson(value = "b",defaultvalue = "20") Integer b) {
        System.out.println("b : " + b);
        return "ok";
    }
    @RequestMapping("/new/test2")
    @ResponseBody
    public String newTest2(Integer b){
        return testService.test1(b);
    }
}
